package edu.java.lectures.lec07.comparable;

public class Apple implements Comparable<Apple> {
    private int weight;

    public Apple(int weight) {
	super();
	this.setWeight(weight);
    }

    public void setWeight(int weight) {
	this.weight = weight;
    }

    public int getWeight() {
	return weight;
    }

    /*
     * if THIS object is "greater" than otherSegment => THIS - OTHER > 0 else if
     * if THIS object is "equals" than otherSegment => THIS - OTHER == 0 else =>
     * THIS object is "smaller" than otherSegment => THIS - OTHER < 0
     */
    @Override
    public int compareTo(Apple otherSegment) {
	if (otherSegment == null) {
	    throw new IllegalArgumentException(
		    "Invalid argument - otherSegment:" + null);
	}
	int myWeight = getWeight();
	int otherSegmentWeight = otherSegment.getWeight();

	int result = myWeight - otherSegmentWeight;
	return result;
    }

    @Override
    public String toString() {
	return weight + "";
    }
}
